package hn.cch.layui_admin.service;


import hn.cch.layui_admin.Message.QueryRequest;
import hn.cch.layui_admin.Message.TableResponse;
import hn.cch.layui_admin.entity.Param;
import hn.cch.layui_admin.repository.ParamRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


@Service
public class ParamService {

    @Autowired
    private ParamRepository paramRepository;

    public TableResponse selectParam(QueryRequest queryRequest){

        Integer page = Integer.valueOf(queryRequest.getPage());
        Integer size = Integer.valueOf(queryRequest.getLimit());
        Pageable pageable = new PageRequest(page, size);
        Page<Param> paramPage = paramRepository.findAll(pageable);
        TableResponse tableResponse = new TableResponse();
        tableResponse.setCode("0");
        tableResponse.setMsg("");
        tableResponse.setCount(String.valueOf(paramPage.getTotalElements()));
        tableResponse.setData(paramPage.getContent());
        return tableResponse;
    }



}
